package com.shtel.bss.saas.tenant.controller;

import com.github.pagehelper.PageInfo;
import com.shtel.bss.saas.core.data.common.controller.DataController;
import com.shtel.bss.saas.tenant.bo.SysRoleBo;
import com.shtel.bss.saas.tenant.dto.SysRoleDTO;
import com.shtel.bss.saas.tenant.mapstrut.EntityDtoMapper;
import com.shtel.bss.saas.tenant.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色表 controller
 *
 * @author xiezhiwei 2020-02-05 22:03
 */
@RestController
@RequestMapping("sys/tenant/sysRole")
public class SysRoleController extends DataController {
    @Autowired
    private ISysRoleService sysRoleService;

    /**
     * 查询角色列表
     */
    @PostMapping("qrySysRoleList")
    public PageInfo<SysRoleDTO> qrySysRoleList(@RequestBody SysRoleDTO sysRoleDTO) {
        PageInfo<SysRoleBo> sysRolePageInfo = sysRoleService.qrySysRoleList(EntityDtoMapper.INSTANCE.toSysRoleBo(sysRoleDTO),
                sysRoleDTO.getPageNum(),
                sysRoleDTO.getPageSize());
        return EntityDtoMapper.INSTANCE.toSysRolePageInfo(sysRolePageInfo);
    }

    /**
     * 查询角色
     */
    @PostMapping("qrySysRole")
    public SysRoleDTO qrySysRole(@RequestBody SysRoleDTO sysRoleDTO) {
        return EntityDtoMapper.INSTANCE.toSysRoleDTO(sysRoleService.qrySysRole(EntityDtoMapper.INSTANCE.toSysRoleBo(sysRoleDTO)));
    }

    /**
     * 保存角色
     *
     * @param sysRoleDTO
     */
    @PostMapping("saveSysRole")
    public void saveSysRole(@RequestBody SysRoleDTO sysRoleDTO) {
        sysRoleService.saveSysRole(EntityDtoMapper.INSTANCE.toSysRoleBo(sysRoleDTO));
    }

    /**
     * 修改角色
     *
     * @param roleId
     * @param sysRoleDTO
     */
    @PutMapping("updateSysRole/{roleId}")
    public void updateSysRole(@PathVariable Long roleId, @RequestBody SysRoleDTO sysRoleDTO) {
        sysRoleService.updateSysRole(EntityDtoMapper.INSTANCE.toSysRoleBo(sysRoleDTO));
    }

    /**
     * 删除用户
     * @param roleId
     */
    @DeleteMapping("deleteSysRole/{roleId}")
    public void deleteSysRole(@PathVariable Long roleId) {
        sysRoleService.removeSysRole(roleId);
    }
}